home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Runimage / Delphi50 / Source / Decision Cube / MXPIVSRC.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-08-11  |  23.3 KB  |  811 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {       Borland Delphi Visual Component Library         }
  4. {                                                       }
  5. {       Copyright (c) 1997,99 Inprise Corporation       }
  6. {                                                       }
  7. {*******************************************************}
  8.  
  9. unit mxpivsrc;
  10.  
  11. interface
  12.  
  13. uses
  14.   Windows, Messages, SysUtils, Classes, Graphics, Grids, Buttons, Controls, StdCtrls,
  15.   Forms, Dialogs, Bde, DB, DBTables, Menus, ExtCtrls,
  16.   mxConsts, mxdb, mxbutton, mxStore, mxcommon;
  17.   
  18. type
  19.   TDecisionButtonPosition = (xtHorizontal, xtVertical, xtLeftTop);
  20.  
  21.   TDecisionPivotOption = (xtRows, xtColumns, xtSummaries);
  22.   TDecisionPivotOptions = set of TDecisionPivotOption;
  23.  
  24.   TDecisionPivot = class;
  25.   TPivotDataLink = class(TDecisionDataLink)
  26.   private
  27.     FPivot: TDecisionPivot;
  28.   protected
  29.     procedure DecisionDataEvent(Event: TDecisionDataEvent); override;
  30.   public
  31.     constructor Create(aPivot: TDecisionPivot);
  32.     destructor Destroy; override;
  33.   end;
  34.  
  35.   TDecisionPivot = class(TCustomPanel)
  36.   private
  37.     FActive: Boolean;
  38.     FDataLink: TPivotDataLink;
  39.     FSource: TDecisionSource;
  40.     FControls: TList;
  41.     FSummaryBox: TPivotButton;
  42.     FInActiveBox: TPivotButton;
  43.     FRowTarget: TPivotButton;
  44.     FColTarget: TPivotButton;
  45.     FRows: Integer;
  46.     FCols: Integer;
  47.     FPages: Integer;
  48.     FExtras: Integer;
  49.     FAutosize: Boolean;
  50.     FStyle:  TDecisionButtonPosition;
  51.     FContents: TDecisionPivotOptions;
  52.     FSpacing: Integer;
  53.     FControlWidth: Integer;
  54.     FControlHeight: Integer;
  55.     FGroupSpacing: Integer;
  56.     FTargetSize: Integer;
  57.     procedure SetAutoSize(Value: Boolean);
  58.     procedure GetButtonSizes(var CellWidth, CellHeight: Integer);
  59.     procedure SetStyle(Style: TDecisionButtonPosition);
  60.     procedure SetContents(Contents: TDecisionPivotOptions);
  61.     procedure SetSpacing(Value: Integer);
  62.     procedure SetControlWidth(Value: Integer);
  63.     procedure SetControlHeight(Value: Integer);
  64.     procedure SetGroupSpacing(Value: Integer);
  65.     procedure SeTDecisionSource(aSource: TDecisionSource);
  66.   protected
  67.     procedure AdjustClientRect(var Rect: TRect); override;
  68.     procedure SetBorderWidth(Value: TBorderWidth);
  69.     function GetBorderWidth: TBorderWidth;
  70.     procedure SetBorderStyle(Value: TBorderStyle);
  71.     function GetBorderStyle: TBorderStyle;
  72.     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  73.     procedure NewPanelSetup;
  74.     procedure NewDimLayout;
  75.     procedure DimStateChange(iDim:Integer);
  76.     property Rows: Integer read FRows;
  77.     property Cols: Integer read FCols;
  78.     property Pages: Integer read FPages;
  79.     property Extras: Integer read FExtras;
  80.   public
  81.     constructor Create(AOwner: TComponent); override;
  82.     destructor Destroy; override;
  83.     procedure SetBounds(Left, Top, Height, Width: Integer); override;
  84.   published
  85.     property ButtonAutoSize: Boolean read FAutoSize write SetAutoSize;
  86.     property DecisionSource: TDecisionSource read FSource write SeTDecisionSource;
  87.     property GroupLayout: TDecisionButtonPosition read FStyle write SetStyle;
  88.     property Groups: TDecisionPivotOptions read FContents write SetContents;
  89.     property ButtonSpacing: Integer read FSpacing write SetSpacing;
  90.     property ButtonWidth: Integer read FControlWidth write SetControlWidth;
  91.     property ButtonHeight: Integer read FControlHeight write SetControlHeight;
  92.     property GroupSpacing: Integer read FGroupSpacing write SetGroupSpacing;
  93.     property BorderWidth: TBorderWidth read GetBorderWidth write SetBorderWidth;
  94.     property BorderStyle: TBorderStyle read GetBorderStyle write SetBorderStyle;
  95.     { from the base class }
  96.     property Align;
  97.     property Alignment;
  98.     property BevelInner;
  99.     property BevelOuter;
  100.     property BevelWidth;
  101.     property DragCursor;
  102.     property DragMode;
  103.     property Enabled;
  104.     property Font;
  105.     property Color;
  106.     property Ctl3D;
  107.     property ParentColor;
  108.     property ParentCtl3D;
  109.     property ParentFont;
  110.     property ParentShowHint;
  111.     property PopupMenu;
  112.     property ShowHint;
  113.     property TabOrder;
  114.     property TabStop;
  115.     property Visible;
  116.     property OnClick;
  117.     property OnDblClick;
  118.     property OnDragDrop;
  119.     property OnDragOver;
  120.     property OnEndDrag;
  121.     property OnEnter;
  122.     property OnExit;
  123.     property OnResize;
  124.     property OnStartDrag;
  125.   end;
  126.  
  127. implementation
  128.  
  129. constructor TDecisionPivot.Create(AOwner: TComponent);
  130. begin
  131.   inherited Create(AOwner);
  132.   { Set default properties of the Decision }
  133.   FActive := True;
  134.   FDataLink := TPivotDataLink.Create(Self);
  135.   FDataLink.FPivot := Self;
  136.   FStyle := xtHorizontal;
  137.   FControlWidth := 64;
  138.   FControlHeight :=24;
  139.   FGroupSpacing := 10;
  140.   FContents := [xtRows, xtColumns, xtSummaries];
  141.   FSpacing := 0;
  142.   FAutosize := True;
  143.   BorderWidth := 0;
  144.   BorderStyle := bsNone;
  145.   NewPanelSetup;
  146.   RCS;
  147. end;
  148.  
  149. destructor TDecisionPivot.Destroy;
  150. var
  151.   i: integer;
  152. begin
  153.   {
  154.     This shouldn't be necessary since these are all ultimately
  155.     owned by the Decision control
  156.   }
  157.   if assigned(FControls) then
  158.   begin
  159.     for I := 0 to FControls.count-1 do
  160.     begin
  161.       TWinControl(FControls[i]).free;
  162.       FControls[i] := nil;
  163.     end;
  164.     FControls.Free;
  165.     FControls := nil;
  166.   end;
  167.   FDataLink.Free;
  168.   FDataLink := nil;
  169.   inherited Destroy;
  170. end;
  171.  
  172. procedure TDecisionPivot.Notification(AComponent: TComponent; Operation: TOperation);
  173. begin
  174.   inherited;
  175.   if (AComponent is TPivotButton) and (Operation = opInsert) then
  176.   begin
  177.     if assigned(DecisionSource) then
  178.       TPivotButton(AComponent).DecisionSource := DecisionSource;
  179.   end;
  180. end;
  181.  
  182. procedure TDecisionPivot.SetBounds(Left, Top, Height, Width: Integer);
  183. begin
  184.   inherited SetBounds(Left,Top,Height,Width);
  185.   NewPanelSetup;
  186. end;
  187.  
  188. var
  189.   Freeing: Boolean = False;
  190.   Lock: Boolean = False;
  191.  
  192.   { Called to set up a whole new layout or change the style }
  193.  
  194. procedure TDecisionPivot.NewPanelSetup;
  195. var
  196.   I: Integer;
  197.   aDimInfo: PDimInfo;
  198.   aButton: TPivotButton;
  199.   DM: TCubeDim;
  200. begin
  201.   if Lock then Exit;
  202.   if (not assigned(DecisionSource)) or not(DecisionSource.Ready) then
  203.   begin
  204.     inherited Caption := inherited Name;
  205.     if assigned(FControls) then
  206.     begin
  207.       DisableAlign;
  208.       try
  209.         for I := 0 to FControls.count-1 do
  210.         begin
  211.           TWinControl(FControls[i]).free;
  212.           FControls[i] := nil;
  213.         end;
  214.       finally
  215.         EnableAlign; 
  216.       end;
  217.     end;
  218.  
  219.     if Freeing then Exit;
  220.     Freeing := True;
  221.     FControls.Free;
  222.     FControls := nil;
  223.     FRowTarget.free;
  224.     FRowTarget := nil;
  225.     FColTarget.free;
  226.     FColTarget := nil;
  227.     FSummaryBox.free;
  228.     FSummaryBox := nil;
  229.     FInactiveBox.free;
  230.     FInactiveBox := nil;
  231.     FRows := 0;
  232.     FCols := 0;
  233.     FPages := 0;
  234.  
  235.     Freeing := False;
  236.     Exit;
  237.   end;
  238.   { Decision source available, so initialize }
  239.   inherited Caption := '';
  240.   FRows := DecisionSource.GetGroupCOunt(dgRow, false);
  241.   FCols := DecisionSource.GetGroupCount(dgCol, false);
  242.   FPages := DecisionSource.GetGroupCount(dgPage, false);
  243.   if assigned(FControls) then
  244.   begin
  245.     if (FControls.count <> (Pages + Rows + Cols)) then
  246.     begin
  247.       for I := 0 to FControls.count-1 do
  248.       begin
  249.         TWinControl(FControls[i]).free;
  250.         FControls[i] := nil;
  251.       end;
  252.       FControls.Free;
  253.       FControls := nil;
  254.     end;
  255.   end;
  256.  
  257.   if not assigned(FControls) then FControls := TList.Create;
  258.   while (FControls.count < (Pages + Rows + Cols)) do
  259.     FControls.Insert(FControls.count, nil);
  260.   { create the summary drop down. }
  261.   if not assigned(FRowTarget) then
  262.   begin
  263.     FRowTarget := TPivotButton.Create(self);
  264.     FRowTarget.Parent := self;
  265.     FRowTarget.iDim := -1;
  266.     FRowTarget.SetType(pbTarget);
  267.     FTargetSize := ButtonHeight;
  268.     aDimInfo := @(FRowTarget.DimInfo);
  269.     aDimInfo.IRowState := [];
  270.     aDimInfo.iGroup := dgRow;
  271.   end;
  272.   if not assigned(FColTarget) then
  273.   begin
  274.     FColTarget := TPivotButton.Create(self);
  275.     FColTarget.Parent := self;
  276.     FColTarget.iDim := -1;
  277.     FColTarget.SetType(pbTarget);
  278.     aDimInfo := @(FColTarget.DimInfo);
  279.     aDimInfo.IRowState := [];
  280.     aDimInfo.iGroup := dgCol;
  281.   end;
  282.   if (xtSummaries in FContents) then
  283.   begin
  284.     if not assigned(FSummaryBox) then
  285.     begin
  286.       Lock := True;
  287.       aButton := TPivotButton.Create(self);
  288.       aButton.parent := self;
  289.       aButton.iDim := -1;
  290.       aButton.SetType(pbSummary);
  291.       aButton.Caption := '';
  292.       FSummaryBox := aButton;
  293.       Lock := False;
  294.     end;
  295.     FExtras := 1;
  296.     for i := 0 to DecisionSource.DecisionCube.DimensionMap.count-1 do
  297.     begin
  298.       DM := DecisionSource.DecisionCube.DimensionMap[i];
  299.       if (not DM.Loaded) and (DM.ActiveFlag <> diInActive) then
  300.       begin
  301.         FExtras := 2;
  302.         break;
  303.       end;
  304.     end;
  305.     if (FExtras = 2) then
  306.     begin
  307.       if not assigned(FInActiveBox) then
  308.       begin
  309.         aButton := TPivotButton.Create(self);
  310.         aButton.parent := self;
  311.         aButton.iDim := -1;
  312.         aButton.SetType(pbInactive);
  313.         aButton.Caption := '';
  314.         FInActiveBox := aButton;
  315.       end;
  316.     end
  317.     else
  318.     begin
  319.       FInactiveBox.free;
  320.       FInactiveBox := nil;
  321.     end;
  322.   end
  323.   else
  324.   begin
  325.     Lock := True;
  326.     FSummaryBox.Free;
  327.     FSummaryBox := nil;
  328.     FInactiveBox.free;
  329.     FInactiveBox := nil;
  330.     Lock := False;
  331.   end;
  332.   { now scan the layout and place individual controls }
  333.   NewDimLayout;
  334. end;
  335.  
  336. {
  337.   This code lays out the controls for the individual dimensions.
  338.   It is called to initialize the controls, then again whenever the
  339.   layout of the controls changes.  Note that it attempts to save existing
  340.   controls where possible, since this code is called for simple pivots as
  341.   well as large scale changes
  342. }
  343.  
  344. procedure TDecisionPivot.NewDimLayout;
  345. var
  346.   i: Integer;
  347.   xControl: TWinControl;
  348.   nSums, nRows, nCols, hmargin, vmargin: Integer;
  349.   CellWidth, CellHeight:Integer;
  350.   delta: Integer;
  351.   IDim: Integer;
  352.   RowX, RowDeltaX, RowY, RowDeltaY: Integer;
  353.   ColX, ColDeltaX, ColY, ColDeltaY: Integer;
  354.   SumX, SumDeltaX, SumY, SumDeltaY: Integer;
  355. begin
  356.   if (not assigned(DecisionSource)) or not(DecisionSource.Ready) then Exit;
  357.   hmargin := inherited BorderWidth;
  358.   vmargin := inherited BorderWidth;
  359.   if (xtRows in FContents) then
  360.     nRows := Rows
  361.   else
  362.     nRows := 0;
  363.   if (xtColumns in FContents) then
  364.     nCols := Cols
  365.   else
  366.     nCols := 0;
  367.   if (xtSummaries in FContents) then
  368.     nSums := Pages + Extras
  369.   else
  370.     nSums := 0;
  371.   GetButtonSizes(CellWidth, CellHeight);
  372.   {
  373.     The row and column controls are placed separately.  An initial position X,Y
  374.     increment DeltaX, DeltaY are set up for both row and column
  375.     The controls are then layed out relative to the position of the first.
  376.   }
  377.   case FStyle of
  378.     xtHorizontal:
  379.     begin
  380.       SumX := hmargin;
  381.       SumY := vmargin;
  382.       SumDeltaX := CellWidth+FSpacing;
  383.       SumDeltaY := 0;
  384.       RowY := vmargin;
  385.       if (xtSummaries in Fcontents) then
  386.         RowX := hMargin + (NSums * (CellWidth + FSpacing)) + FGroupSpacing - FSpacing
  387.       else
  388.         RowX := hmargin;
  389.       RowDeltaX := CellWidth+FSpacing;
  390.       RowDeltaY := 0;
  391.       if (xtRows in FContents) then
  392.         ColX := RowX + GroupSpacing + (RowDeltaX * nRows) + FTargetSize
  393.       else
  394.         ColX := RowX;
  395.       ColDeltaX := RowDeltaX;
  396.       ColY := RowY;
  397.       ColDeltaY := RowDeltaY;
  398.       FRowTarget.Width := FTargetSize;
  399.       FRowTarget.Height := CellHeight;
  400.       FColTarget.Width := FTargetSize;
  401.       FColTarget.Height := CellHeight;
  402.       FRowTarget.Left := RowX;
  403.       FRowTarget.Top := RowY;
  404.       FColTarget.Left := ColX;
  405.       FColTarget.Top := ColY;
  406.       RowX := RowX + FTargetSize + FSpacing;
  407.       ColX := ColX + FTargetSize + FSpacing;
  408.     end;
  409.     xtVertical:
  410.     begin
  411.       SumX := hmargin;
  412.       SumY := vmargin;
  413.       SumDeltaX := 0;
  414.       SumDeltaY := CellHeight + FSpacing;
  415.       RowX := hmargin;
  416.       if (xtSummaries in FContents) then
  417.         RowY := vmargin + (nSums * (CellHeight + FSpacing)) + FGroupSpacing - Fspacing
  418.       else
  419.         RowY := vmargin;
  420.       RowDeltaX := 0;
  421.       RowDeltaY := CellHeight + FSpacing;
  422.       ColX := RowX;
  423.       ColDeltaX := RowDeltaX;
  424.       if (xtRows in FContents) then
  425.         ColY := RowY + (nRows*RowDeltaY) + FGroupSpacing +FTargetSize
  426.       else
  427.         ColY := RowY;
  428.       ColDeltaY := RowDeltaY;
  429.       FRowTarget.Width := CellWidth;
  430.       FRowTarget.Height := FTargetSize;
  431.       FColTarget.Width := CellWidth;
  432.       FColTarget.Height := FTargetSize;
  433.       FRowTarget.Left := RowX;
  434.       FRowTarget.Top := RowY;
  435.       FColTarget.Left := ColX;
  436.       FColTarget.Top := ColY;
  437.       RowY := RowY + FTargetSize + FSpacing;
  438.       ColY := ColY + FTargetSize + FSpacing;
  439.     end;
  440.     else
  441.     begin
  442.       SumX := hmargin;
  443.       SumY := vmargin;
  444.       SumDeltaX := CellWidth+FSpacing;
  445.       SumDeltaY := 0;
  446.       RowX := hmargin;
  447.       RowDeltaX := 0;
  448.       if (xtSummaries in FContents) then
  449.         RowY := cellHeight + vmargin
  450.       else
  451.         RowY := vmargin;
  452.       RowDeltaY := FSpacing + CellHeight;
  453.       delta := (Height - (nRows * RowDeltaY) - FTargetSize - RowY - vmargin)div 2;
  454.       if (delta > 0) then RowY := RowY + delta;
  455.       if (xtSummaries in Fcontents) then
  456.         ColX := cellWidth + hmargin
  457.       else
  458.         ColX := hmargin;
  459.       ColDeltaX := CellWidth + FSpacing;
  460.       delta := (Width - (nCols * ColDeltaX) - FTargetSize - ColX - hmargin) div 2;
  461.       if (delta >= 0) then ColX := ColX + delta;
  462.       ColY := vmargin;
  463.       ColDeltaY := 0;
  464.       FRowTarget.Width := CellWidth;
  465.       FRowTarget.Height := FTargetSize;
  466.       FColTarget.Width := FTargetSize;
  467.       FColTarget.Height := CellHeight;
  468.       FRowTarget.Left := RowX;
  469.       FRowTarget.Top := RowY;
  470.       FColTarget.Left := ColX;
  471.       FColTarget.Top := ColY;
  472.       RowY := RowY + FTargetSize + FSpacing;
  473.       ColX := ColX + FTargetSize + FSpacing;
  474.     end;
  475.   end;
  476.   if not (xtRows in FContents) then FRowTarget.Left := 10000;
  477.   if not (xtColumns in FContents) then FColTarget.Left := 10000;
  478.   { Scan the rows, creating the necessary control and positioning it }
  479.   if assigned(FSummaryBox) then
  480.   begin
  481.     TPivotButton(FSummaryBox).SetBounds(SumX, SumY, cellWidth, cellHeight);
  482.     SumX := SumX + SumDeltaX;
  483.     SumY := SumY + SumDeltaY;
  484.   end;
  485.   if assigned(FInactiveBox) then
  486.   begin
  487.     TPivotButton(FInactiveBox).SetBounds(SumX, SumY, cellWidth, cellHeight);
  488.     SumX := SumX + SumDeltaX;
  489.     SumY := SumY + SumDeltaY;
  490.   end;
  491.   if (Pages > 0) then
  492.     for I := 0 to Pages-1 do
  493.     begin
  494.       with DecisionSource do
  495.         iDim := DecisionSource.GetActiveDim(dgPage, i, false);
  496.  
  497.       DimStateChange(iDim);  { set up the control for this dimension }
  498.       xControl := FControls[iDim];
  499.       xControl.Height := CellHeight;
  500.       xControl.Width := CellWidth;
  501.       xControl.Left := SumX;
  502.       xControl.Top := SumY;
  503.       if not (xtSummaries in FContents) then
  504.         xControl.Left := 10000;
  505.       SumX := SumX + SumDeltaX;
  506.       SumY := SumY + SumDeltaY;
  507.     end;
  508.   if (Rows > 0) then
  509.     for I := 0 to Rows-1 do
  510.     begin
  511.       with DecisionSource do
  512.         iDim := DecisionSource.GetActiveDim(dgRow, i, false);
  513.       DimStateChange(iDim);  { set up the control for this dimension }
  514.       xControl := FControls[iDim];
  515.       xControl.Height := CellHeight;
  516.       xControl.Width := CellWidth;
  517.       xControl.Left := RowX;
  518.       xControl.Top := RowY;
  519.       if not (xtRows in FContents) then xControl.Left := 10000;
  520.       RowX := RowX + RowDeltaX;
  521.       RowY := RowY + RowDeltaY;
  522.     end;
  523.     { Scan the Columns, creating the necessary control and positioning it }
  524.     if (Cols > 0) then
  525.       for I := 0 to Cols-1 do
  526.       begin
  527.         with DecisionSource do
  528.           IDim := DecisionSource.GetActiveDim(dgCol, i, false);
  529.         DimStateChange(iDim);  { set up the control for this dimension }
  530.         xControl := FControls[iDim];
  531.         xControl.Height := CellHeight;
  532.         xControl.Width := CellWidth;
  533.         xControl.Left := ColX;
  534.         xControl.Top := ColY;
  535.         if not (xtColumns in FContents) then xControl.Left := 10000;
  536.         ColX := ColX + ColDeltaX;
  537.         ColY := ColY + ColDeltaY;
  538.       end;
  539.   { Now set up all the owned components }
  540.   for i := 0 to ControlCount-1 do
  541.   begin
  542.     if (Controls[i] is TPivotButton) then
  543.     begin
  544.       TPivotButton(Controls[i]).NewState;
  545.     end;
  546.   end;
  547. end;
  548.  
  549. procedure TDecisionPivot.GetButtonSizes(var CellWidth, CellHeight: Integer);
  550. var
  551.   hmargin, vmargin, nRows, nCols: Integer;
  552.   temp: Integer;
  553.   nSummary: Integer;
  554. begin
  555.   hmargin := inherited BorderWidth;
  556.   vmargin := inherited BorderWidth;
  557.   if (xtRows in FContents) then
  558.     nRows := Rows
  559.   else
  560.     nRows := 0;
  561.   if (xtColumns in FContents) then
  562.     nCols := Cols
  563.   else
  564.     nCols := 0;
  565.   if (xtSummaries in FContents) then
  566.     nSummary := Pages + Extras
  567.   else
  568.     nSummary := 0;
  569.   CellWidth := FControlWidth;
  570.   CellHeight := FControlHeight;
  571.   if FAutoSize then
  572.   begin
  573.     if (FStyle = xtHorizontal) then
  574.     begin
  575.       CellHeight := Height - 2*vmargin;
  576.       CellWidth := Width - 2*hmargin;
  577.       if (xtSummaries in FContents) then
  578.       begin
  579.         if ((nRows + nCols) > 0) then CellWidth := CellWidth - FGroupSpacing;
  580.       end;
  581.       temp := nSummary;
  582.       if (temp > 1) then
  583.         CellWidth := CellWidth - ((temp-1) * FSpacing);
  584.       temp := nRows;
  585.       if (xtRows in FContents) then temp := temp + 1;
  586.       if (temp > 1) then
  587.         CellWidth := CellWidth - ((temp-1) * FSpacing);
  588.       temp := nCols;
  589.       if (xtColumns in FContents) then temp := temp + 1;
  590.       if (temp > 1) then
  591.         CellWidth := CellWidth - ((temp-1) * FSpacing);
  592.       if (xtRows in FContents) then
  593.         CellWidth := CellWidth - FTargetSize;
  594.       if (xtColumns in FContents) then
  595.         CellWidth := CellWidth - FTargetSize;
  596.       if (xtRows in FContents) and (xtColumns in FContents) then
  597.         CellWidth := CellWidth - FGroupSpacing;
  598.       if ((nRows + nCols + nSummary) > 1) then
  599.         CellWidth := CellWidth div (nRows + nCols + nSummary);
  600.     end;
  601.     if (FStyle = xtVertical) then
  602.     begin
  603.       CellWidth := Width - 2*hmargin;
  604.       { now calculate the height }
  605.       CellHeight := Height - 2*vmargin;
  606.       if (xtSummaries in FContents) then
  607.       begin
  608.         if ((nRows + nCols) > 0) then
  609.           CellHeight := CellHeight - FGroupSpacing;
  610.       end;
  611.       temp := nSummary;
  612.       if (temp > 1) then
  613.         CellHeight := CellHeight - ((temp-1) * FSpacing);
  614.       temp := nRows;
  615.       if (xtRows in FContents) then temp := temp + 1;
  616.       if (temp > 1) then
  617.         CellHeight := CellHeight - ((temp-1) * FSpacing);
  618.       temp := nCols;
  619.       if (xtColumns in FContents) then temp := temp + 1;
  620.       if (temp > 1) then
  621.         CellHeight := CellHeight - ((temp-1) * FSpacing);
  622.       if (xtRows in FContents) then
  623.         CellHeight := CellHeight - FTargetSize;
  624.       if (xtColumns in FContents) then
  625.         CellHeight := CellHeight - FTargetSize;
  626.       if (xtRows in FContents) and (xtColumns in FContents) then
  627.         CellHeight := CellHeight - FGroupSpacing;
  628.       if ((nRows + nCols + nSummary) > 1) then
  629.         CellHeight := CellHeight div (nRows + nCols + nSummary);
  630.     end;
  631.   end;
  632. end;
  633.  
  634. {
  635.   This code is used to create and maintain a control for a single dimension
  636.   Note that once created, the control is kept around if it is still of
  637.   the appropriate type.
  638. }
  639.  
  640. procedure TDecisionPivot.DimStateChange(iDim: Integer);
  641. var
  642.   xControl: TWinControl;
  643.   xButton: TPivotButton;
  644.   aString: String;
  645. begin
  646.   if not DecisionSource.ready then Exit;
  647.   xControl := FControls[iDim];  { get any old control for this dim. }
  648.   if (xControl = nil) or (xControl.Classname <> 'TPivotButton') then
  649.   begin
  650.     if assigned(xControl) then aString := xControl.Classname;
  651.     xButton := TPivotButton.Create(self);
  652.     xButton.parent := self;
  653.     xButton.AllowAllUp := true;
  654.     xButton.GroupIndex := iDim + 100;
  655.     if assigned(xControl) then
  656.       xButton.setBounds(xControl.Left,xControl.Top,xControl.Width,xControl.Height);
  657.     xControl.Free;
  658.     xControl := TWinControl(xButton);
  659.   end;
  660.   xButton := TPivotButton(XControl);
  661.   xButton.iDim := iDim;
  662.   FControls[iDim] := xControl;  { Keep the control in the control list }                                                                 // to manage the control palette
  663. end;
  664.  
  665. {
  666.   Handle exposed properties
  667. }
  668. procedure TDecisionPivot.SeTDecisionSource(aSource: TDecisionSource);
  669. begin
  670.   { hook the change events of the Decision grid }
  671.   FSource := aSource;
  672.   FDataLink.DecisionSource := aSource;
  673.   if (FSource <> nil) then
  674.   begin
  675.     NewPanelSetup;
  676.   end;
  677. end;
  678.  
  679. procedure TDecisionPivot.SetStyle(Style: TDecisionButtonPosition);
  680. begin
  681.   FStyle := Style;
  682.   NewPanelSetup;
  683. end;
  684.  
  685. procedure TDecisionPivot.SetContents(Contents: TDecisionPivotOptions);
  686. begin
  687.   FContents := Contents;
  688.   NewPanelSetup;
  689. end;
  690.  
  691. procedure TDecisionPivot.SetAutoSize(Value: boolean);
  692.  
  693. begin
  694.   FAutosize := Value;
  695.   NewPanelSetup;
  696. end;
  697.  
  698. procedure TDecisionPivot.SetSpacing(Value: Integer);
  699. begin
  700.   FSpacing := Value;
  701.   NewPanelSetup;
  702. end;
  703.  
  704. procedure TDecisionPivot.SetControlWidth(Value: Integer);
  705. begin
  706.   FControlWidth := Value;
  707.   NewPanelSetup;
  708. end;
  709.  
  710. procedure TDecisionPivot.SetControlHeight(Value: Integer);
  711. begin
  712.   FControlHeight := Value;
  713.   NewPanelSetup;
  714. end;
  715.  
  716. procedure TDecisionPivot.SetGroupSpacing(Value: Integer);
  717. begin
  718.   FGroupSpacing := Value;
  719.   NewPanelSetup;
  720. end;
  721.  
  722. function TDecisionPivot.GetBorderWidth: TBorderWidth;
  723. begin
  724.   Result := inherited BorderWidth;
  725. end;
  726.  
  727. function TDecisionPivot.GetBorderStyle: TBorderStyle;
  728. begin
  729.   Result := inherited BorderStyle;
  730. end;
  731.  
  732. procedure TDecisionPivot.AdjustClientRect(var Rect: TRect);
  733. begin
  734.   case FStyle of
  735.     xtLeftTop:
  736.     begin
  737.       Rect.Left := ButtonWidth + BorderWidth;
  738.       Rect.Top := ButtonHeight + BorderWidth;
  739.     end;
  740.     xtVertical:
  741.     begin
  742.       Rect.Left := ButtonWidth + BorderWidth;
  743.     end;
  744.     xtHorizontal:
  745.     begin
  746.       Rect.Top := ButtonHeight + BorderWidth;
  747.     end;
  748.   end;
  749.   inherited AdjustClientRect(Rect);
  750. end;
  751.  
  752. procedure TDecisionPivot.SetBorderWidth(Value: TBorderWidth);
  753. begin
  754.   inherited BorderWidth := Value;
  755.   NewPanelSetup;
  756. end;
  757.  
  758. procedure TDecisionPivot.SetBorderStyle(Value: TBorderStyle);
  759. begin
  760.   inherited BorderStyle := Value;
  761.   NewPanelSetup;
  762. end;
  763.  
  764.   { Event handlers for other objects external events }
  765.  
  766.   { Datalink Methods }
  767.  
  768. procedure TPivotDataLink.DecisionDataEvent(Event: TDecisionDataEvent);
  769. begin
  770.   if not assigned(fPivot) then Exit;
  771.   if FBlocked then Exit;
  772.   FBlocked := True;
  773.   case Event of
  774.     xeSummaryChanged:
  775.     begin
  776.       FPivot.Invalidate;
  777.     end;
  778.     xePivot:
  779.     begin
  780.       FPivot.NewPanelSetup;
  781.     end;
  782.     xeStateChanged:
  783.     begin
  784.       FPivot.NewPanelSetup;
  785.     end;
  786.     xeNewMetaData:
  787.     begin
  788.       FPivot.NewPanelSetup;
  789.     end;
  790.     xeSourceChange:
  791.     begin
  792.       FPivot.SetDecisionSource(FDecisionSource);
  793.       FPivot.NewPanelSetup;
  794.     end;
  795.   end;
  796.   FBlocked := False;
  797. end;
  798.  
  799. constructor  TPivotDataLink.Create(aPivot: TDecisionPivot);
  800. begin
  801.   FPivot := APivot;
  802. end;
  803.  
  804. destructor TPivotDataLink.Destroy;
  805. begin
  806.   inherited Destroy;
  807. end;
  808.  
  809. end.
  810.  
  811.